<template>
	<view class="station-item">
		<view class="content">
			<view class="item-header">
				<view class="index">
					{{ data.stationNo < 10 ? `0${data.stationNo}` : data.stationNo }}
				</view>
				<view class="processes">
					<text class="text">{{$t('components.stationItem.5q5bqmvsbs00')}}</text>
						<view class="processes-list">
						<view class="processes-item" v-for="(left, index) in data.processesDtos" :key="left.id">
							<!-- 0{{left.processNo}} -->
							{{ left.processNo < 10 ? `0${left.processNo}` : left.processNo }}
						</view>
					</view>
					
				</view>
			</view>
			<view class="item-info">
				<view class="device-info">
					<image src="../../../../static/icons/device.svg"></image>
					<view class="input" @click="handlerShowVrCode(1)">
						<u-input disabled v-model="deviceText"></u-input>
					</view>
					<view class="icon" @click.stop="deleteDevice(1)" >
						<u-icon v-if="deviceText" class="icon" name="close-circle" color="#3E8FF7" size="20"></u-icon>
					</view>
				</view>
				<view class="person-info">
					<image src="../../../../static/icons/person.svg"></image>
					<view class="input" @click="handlerShowVrCode(2)">
						<u-input disabled v-model="personText"></u-input>
					</view>
					<view class="icon" @click.stop="deletePerson(2)" >
						<u-icon v-if="personText" class="icon" name="close-circle" color="#3E8FF7" size="20"></u-icon>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {}
		},
		computed: {
			deviceText: {
				get() {

					let current = this.currentDeviceMap && this.currentDeviceMap[this.data.id]

					if(!current || !current.deviceSn) return ""
					return `${current.deviceSn}-${current.deviceType}`
				},
				set(val) {
				}
			},
			personText: {
				get() {
					let current = this.currentPersonMap && this.currentPersonMap[this.data.id]
					if(!current) return ""
					return current.realName
				},
				set(val) {
				}
			}
		},
		props:{
			data:Object,
			index: Number,
			currentDeviceMap: Object,
			currentPersonMap: Object
		},
		methods: {
			handlerShowVrCode(type) {
				this.$emit('tapClick', type)
			},
			deleteDevice(event) {
				var that = this
				uni.showModal({
					content:`${this.$t('production.AdjustContent.isSureDelete')}0${that.data.stationNo}${this.$t('production.AdjustContent.of')}${event === 1 ? this.$t('production.AdjustContent.5q5bj3756jg0') : this.$t('production.AdjustContent.5q5bj3756v80')}?`,
					confirmText:this.$t('modal.ok'),
					cancelText:this.$t('modal.cancel'),
					success: function (res) {
					if (res.confirm) {
						that.$set(that.currentDeviceMap, that.data.id, '')
						that.$emit('deleteItem', 'device', that.data)
					} else if (res.cancel) {
						console.log('用户点击取消');
					}
				}
				})
				
			}, 
			deletePerson(event) {
				var that = this
				uni.showModal({
					content:`${this.$t('production.AdjustContent.isSureDelete')}0${that.data.stationNo}${this.$t('production.AdjustContent.of')}${event === 1 ? this.$t('production.AdjustContent.5q5bj3756jg0') : this.$t('production.AdjustContent.5q5bj3756v80')}?`,
					confirmText:this.$t('modal.ok'),
					cancelText:this.$t('modal.cancel'),
					success: function (res) {
					if (res.confirm) {
						that.$set(that.currentPersonMap, that.data.id, '')
						that.$emit('deleteItem', 'person', that.data)
					} else if (res.cancel) {
						console.log('用户点击取消');
					}
				}
				})
				
			}
		}
	}
</script> 

<style lang="scss">
	.station-item {
		width: 100%;
		background: #ffffff;
		.content {
			padding: 10rpx;
			.item-header{
				display: flex;
				font-family: AlibabaPuHuiTi;
				font-size: 16rpx;
				font-weight: 500;
				line-height: 36rpx;
				text-align: center;
				letter-spacing: 0em;
				.index {
					color: #3E8FF7;
				}
				.processes {
					color: #333333;
					margin-left: 15rpx;
					display: flex;
					flex: 1;
					align-items: center;
					text-align: left;
					.text {
					  flex: 0 0 60rpx;
					  text-align: center;
					}
					.processes-list {
						flex: 1;
						.processes-item {
							display: inline-block;
							width: 50rpx;
							height: 24rpx;
							line-height: 24rpx;
							text-align: center;
							border-radius: 2px;
							opacity: 1;
							font-family: AlibabaPuHuiTi;
							font-size: 16rpx;
							font-weight: normal;
							background: #E1FFE4;
							color: #46C253;
							box-sizing: border-box;
							border: 1px solid #46C253;
							margin-left: 10rpx;
						}
					}
				}
			}
		}
		.item-info {
			.device-info,.person-info {
				display: flex;
				image {
					width: 20rpx;
					flex: 0 0 20rpx;
					height: 20rpx;
					margin-top: 16rpx;
				}
				.input {
					margin-left: 15rpx;
					// height: 50rpx !important;
					flex: 0 0 260rpx;
					margin-top: 10rpx;
				}
				.icon {
					width: 20px;
					margin-left: 5rpx;
					// height: 50rpx !important;
					flex: 0 0 20rpx;
					margin-top: 7rpx;
				}
				
			}
			::v-deep .u-input {
			    height: 30rpx !important;
				width: 260rpx;
			}
		}
	}
</style>